package com.sophimp.award.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.sophimp.award.bean.AwardItem

/**
 * create by sfx on 2022/8/9 11:52
 */
@Database(
    version = 1, exportSchema = false,
    entities = [AwardItem::class]
)
abstract class AwardDb : RoomDatabase() {

    companion object {
        private var instance: AwardDb? = null
        fun getDb(ctx: Context): AwardDb {
            if (instance == null) {
                instance =
                    Room.databaseBuilder(ctx.applicationContext, AwardDb::class.java, "award.db")
//                        .addMigrations()
                        .allowMainThreadQueries()
                        .build()
            }
            return instance!!
        }
    }

    abstract fun getAwardItemDao(): AwardItemDao
}